<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                xmlns:lxslt="http://xml.apache.org/xslt"
                xmlns:redirect="http://xml.apache.org/xalan/redirect"
                extension-element-prefixes="redirect">

    <xsl:template match="folder">
        <xsl:param name="parent-folder"/>
        <xsl:param name="parent-name"/>
        <xsl:variable name="name" select="@name"/>

            <xsl:variable name="new-path">
                <xsl:call-template name="from-dos">
                    <xsl:with-param name="path" select="@name"/>
                </xsl:call-template>
            </xsl:variable>
            <redirect:write file="{$output.dir}/files/{$parent-folder}{$new-path}summary.html">
                <html>
                    <head>
                        <link rel="stylesheet" type="text/css">
                            <xsl:attribute name="href">
                                <xsl:call-template name="path">
                                    <xsl:with-param name="path"
                                                    select="concat($parent-folder,$new-path,'summary.html')"/>
                                </xsl:call-template>
                                <xsl:text>stylesheet.css</xsl:text>
                            </xsl:attribute>
                        </link>
                    </head>
                    <body>
                        <xsl:call-template name="pageHeader"/>
                        <h3>Folder
                            <xsl:value-of select="concat($parent-name,@name)"/>
                        </h3>

                        <xsl:if test="count(../folder[@name = $name]/folder) > 0">
                            <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
                                <tr>
                                    <th>Folder</th>
                                    <th>Files</th>
                                    <th>Errors</th>
                                </tr>
                                <xsl:for-each select="../folder[@name = $name]/folder">
                                    <xsl:variable name="sub-path">
                                        <xsl:call-template name="from-dos">
                                            <xsl:with-param name="path" select="@name"/>
                                        </xsl:call-template>
                                    </xsl:variable>
                                    <tr>
                                        <xsl:call-template name="alternated-row"/>
                                        <td>
                                            <a target="mainFrame">
                                                <xsl:attribute name="href">
                                                    <xsl:value-of select="$sub-path"/>
                                                    <xsl:text>summary.html</xsl:text>
                                                </xsl:attribute>
                                                <xsl:value-of select="@name"/>
                                            </a>
                                        </td>
                                        <td>
                                            <xsl:value-of select="count(.//file)"/>
                                        </td>
                                        <td>
                                            <xsl:value-of select="count(.//error)"/>
                                        </td>
                                    </tr>
                                </xsl:for-each>
                            </table>
                        </xsl:if>

                        <xsl:if test="count(../folder[@name = $name]/file) > 0">
                        <table class="log" border="0" cellpadding="5" cellspacing="2" width="100%">
                            <tr>
                                <th>File</th>
                                <th>Errors</th>
                            </tr>
                            <xsl:for-each select="../folder[@name = $name]/file">
                                <tr>
                                    <xsl:call-template name="alternated-row"/>
                                    <td>
                                        <a target="mainFrame">
                                            <xsl:attribute name="href">
                                                <xsl:value-of select="@path"/>
                                                <xsl:text>.html</xsl:text>
                                            </xsl:attribute>
                                            <xsl:value-of select="@path"/>
                                        </a>
                                    </td>
                                    <td>
                                        <xsl:value-of select="count(./error)"/>
                                    </td>
                                </tr>
                            </xsl:for-each>
                        </table>
                        </xsl:if>
                    </body>
                </html>
            </redirect:write>


            <xsl:apply-templates select="folder">
                <xsl:with-param name="parent-folder" select="concat($parent-folder, $new-path)"/>
                <xsl:with-param name="parent-name" select="concat($parent-name, $name)"/>
            </xsl:apply-templates>
            <xsl:apply-templates select="file"/>

    </xsl:template>

</xsl:stylesheet>